package org.hxzon.cyclone;

import java.util.List;

import org.hxzon.cyclone.pcontacts.ParticleContact;
import org.hxzon.cyclone.pcontacts.ParticleContactGenerator;

//pworld.h
//与地面的碰撞
public class GroundContacts implements ParticleContactGenerator {
    private List<Particle> particles;

    public void init(List<Particle> particles) {
        this.particles = particles;
    }

    public int addContact(List<ParticleContact> contacts) {
        int count = 0;
        for (Particle p : particles) {
            double y = p.getPosition().y;
            if (y < 0.0f) {
                ParticleContact contact = new ParticleContact();
                contacts.add(contact);

                contact.contactNormal = Vector3.UP;
                contact.particle[0] = p;
                contact.particle[1] = null;
                contact.penetration = -y;
                contact.restitution = 0.2f;
                count++;
            }

        }
        return count;
    }
}
